import re


class Setting(object):
    "Setting基本类"
    def __init__(self, head: dict):
        for key, value in head.items():
            self.__dict__[key] = value


def load_txt(file: str):
    "读取txt类型的配置文件"

    head = {}
    with open(file) as f:
        data = f.readlines()
        for da in data:
            das = re.match(r"(^\w.*?)\s*?=\s*?([\w\.]+\w).*?$", da, re.S)
            if not(das is None):
                head[das.group(1)] = das.group(2)

    return Setting(head)


def load_class(obj: type):
    return Setting(obj().__dict__)


def load(f: str or type):
    if isinstance(f, str):
        return load_txt(f)
    elif isinstance(f, type):
        return load_class(f)